package com.github.winyiwin.archetypes.api.impl;

import com.github.winyiwin.archetypes.api.dto.DemoDTO;
import com.github.winyiwin.archetypes.api.dto.ResultDTO;
import org.apache.dubbo.config.annotation.Service;
import com.github.winyiwin.archetypes.api.service.QuickstartService;
import org.apache.dubbo.rpc.RpcContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Service(version = "1.0.0")
public class QuickstartServiceImpl implements QuickstartService {
    private static final Logger logger = LoggerFactory.getLogger(QuickstartServiceImpl.class);

    @Override
    public String sayHello(String name) {
        logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
    }

    @Override
    public ResultDTO getDemo(Long id) {
        DemoDTO demoDTO = new DemoDTO();
        demoDTO.setId(id);
        demoDTO.setMessage("SUCCESS");
        return ResultDTO.success(demoDTO);
    }

}
